<template>
  <el-checkbox-group v-bind="$attrs" :value="value" v-on="$listeners">
    <el-checkbox
      v-for="item in options"
      :key="item.value || item.label"
      :disabled="!!item.disabled"
      :label="item.value || item.label"
      :class="checkboxClass"
    >
      {{ item.label }}
    </el-checkbox>
  </el-checkbox-group>
</template>

<script>
const toString = Object.prototype.toString

export default {
  name: 'CCheckboxGroup',
  data() {
    return {}
  },
  props: {
    value: {
      default: () => [],
    },
    checkboxClass: String,
  },
  computed: {
    options() {
      const { options = [] } = this.$attrs
      if (toString.call(options) === '[object Object]') {
        return Object.keys(options).map(key => {
          return { value: key, label: options[key] }
        })
      }
      return options
    },
  },
}
</script>
